package es.efor.ics.gev.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Version;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

/**
 * The persistent class for the <b>PROGRAMAS</b> database table.
 * 
 * @author dlisbona
 *
 */
@Entity
@Table(name = "PROGRAMAS")
public class Programa extends BaseObject implements Serializable {

	// static data
	private static final long serialVersionUID = -5859449536162939333L;

	// private instance data
	private Long id;
	private String descripcion;
	private Modulo modulo;
	private Integer version;
	
	/**
	 * Construct an uninitialized <code>Programa</code> (for runtime proxy
	 * generation in Hibernate).
	 */
	protected Programa() {		
	}
	
	// ********************** Accessor Methods ********************** //
	
	@Id
	@Column(name = "PROGRAMA_MODULO_ID")
	@GeneratedValue(generator = "foreign")
	@GenericGenerator(
			name = "foreign", 
			strategy = "foreign", 
			parameters = { 
					@Parameter(
							name = "property", 
							value = "modulo") })
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	@OneToOne(mappedBy="programa", optional=false, fetch=FetchType.LAZY)
	public Modulo getModulo() {
		return modulo;
	}

	public void setModulo(Modulo modulo) {
		this.modulo = modulo;
	}
	
	@Column(name = "DESCRIPCION", length = 255, nullable = false)
	public String getDescripcion() {
		return descripcion;
	}
	
	public void setDescripcion(String descripcion) {
		this.descripcion = descripcion;
	}

	@Version
	@Column(name = "OBJ_VERSION")
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	// ********************** Common Methods ********************** //
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof FichaConocimiento == false) {
			return false;
		}
		if (this == obj) {
			return true;
		}
		Programa rhs = (Programa) obj;	
		// TODO Auto-generated method stub
		return EqualsBuilder.reflectionEquals(this, rhs);
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return HashCodeBuilder.reflectionHashCode(this);
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
	      return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
	}

}
